<?php

class Helper_Info {

	public function save($type_info){
		global $_WGT;
		$info_type = in_array($info_type,array('text','single','mutli')) ? 'common' : $type_info;
		$table  = 'Model_Info'.ucfirst($info_type);
		$cate_id = isset($_POST['cate_id']) ? (int)$_POST['cate_id']         : '';
		if(!$cate_id) $cate_id = $this->save_cate($info_type);
		$keyword = isset($_POST['keyword']) ? str_inmysql($_POST['keyword']) : '';
		if(!$keyword) ajax_feedback(0, 1201);
        $keyword = str_replace(array(';','，'),',',$_POST['keyword']);
        
        if($info_type=='common'){
			$detail = array();
			$detail['customer_id']       = $_SESSION['customer_id'];
			$detail['keyword']           = $keyword;
			$detail['cate_id']           = $cate_id>0 ? $cate_id : $this->save_cate($info_type);
			$detail['info_type']         = empty($_POST['info_type'])         ? '' : str_inmysql($_POST['info_type']);
			$detail['info_title']        = empty($_POST['info_title'])        ? '' : str_inmysql($_POST['info_title']);
			$detail['info_pic']          = empty($_POST['info_pic'])          ? '' : str_inmysql($_POST['info_pic']);
			$detail['pic_showincontent'] = empty($_POST['pic_showincontent']) ? '' : str_inmysql($_POST['pic_showincontent']);
			$detail['info_intro']        = empty($_POST['info_intro'])        ? '' : str_inmysql($_POST['info_intro']);
			$detail['info_desc']         = empty($_POST['info_desc'])         ? '' : str_inmysql($_POST['info_desc']);
			$detail['info_url']          = empty($_POST['info_url'])          ? '' : str_inmysql($_POST['info_url']);
			$detail['create_date']       = date('Y-m-d H:i:s',$_WGT['TIME']);
        }
	} 

	public function save_cate($info_type){
		$data = array();
		$data['customer_id'] = $_SESSION['customer_id'];
		$data['info_type'] = $info_type;
		$data['cate_name'] = '默认';
		$cateModel = new Model_InfoCate();
		return $cateModel->insert($data);
	}

}

